from flask import Flask, request
from database import db
from flask_cors import CORS
from coupon import bp_coupon
from goods import bp_goods
from user import bp_user

app = Flask(__name__)
# 注册蓝图
app.register_blueprint(bp_coupon, url_prefix='/coupon')
app.register_blueprint(bp_goods)
app.register_blueprint(bp_user, url_prefix='/user')
app.register_blueprint(bp_goods, url_prefix='/carM')
cors = CORS(app)


@app.route('/find')
def find():
    sql = 'select * from myapp_login'
    res = db.findall(sql)

    for i in res:
        print(i)
    return 'ok'


@app.route('/findone')
def findone():
    sql = 'select * from myapp_login where id=6'
    res = db.findone(sql)
    print(res)
    return 'ok'


@app.route('/add', methods=['POST', 'GET'])
def add():
    # request.form  request.args  request.data
    name = request.form.get('name')
    password = request.form.get('password')
    # 给老师表加入数据
    sql = "insert into myapp_login(name,password) values('%s','%s')" % (name, password)
    db.insert(sql)
    return 'ok'


@app.route('/delete')
def delete():
    sql = 'delete from myapp_login where id=3'
    db.insert(sql)
    return 'ok'


if __name__ == '__main__':
    app.run(debug=True)
